package org.hot100_2;

import org.leetcode.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class leetcode114 {
    public void flatten(TreeNode root) {
        List<Integer> list = new ArrayList<>();

        method(root,list);
        TreeNode cur = root;
        for (int i = 1; i < list.size(); i++) {
            cur.right=new TreeNode(list.get(i));
            cur.left=null;
            cur=cur.right;
        }
    }

    private void method(TreeNode root, List<Integer> list){
        if (root==null){
            return;
        }
        list.add(root.val);
        method(root.left,list);
        method(root.right,list);
    }
}
